package org.changchen.fgt.filter;

import java.io.IOException;

import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.annotation.WebFilter;
import javax.servlet.http.HttpServletRequest;

import org.changchen.fgt.constant.GlobalConstants;
import org.changchen.fgt.utils.ApplicationContextUtil;
import org.changchen.fgt.utils.HttpUtil;
import org.springframework.stereotype.Component;

@Component
@WebFilter(urlPatterns = {"/**"}, filterName = "normalWebFilter")
public class NormalWebFilter implements Filter{
	

	@Override
	public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
			throws IOException, ServletException {
		
		HttpServletRequest httpRequest = (HttpServletRequest)request;		
		
		// 判断是否是从 移动端 访问
		Boolean isMobile = HttpUtil.isFromMobile(httpRequest);
		ApplicationContextUtil.set(GlobalConstants.ISMOBILE, isMobile);
		
		
		chain.doFilter(request, response);
	}

	
	
}
